package com.brsya.movie.ksAd;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

import com.brsya.movie.R;
import com.kwad.sdk.api.KsAdSDK;
import com.kwad.sdk.api.KsContentPage;
import com.kwad.sdk.api.KsScene;

/**
 * 媒体分享后进入的页面
 */
public class TestMediaShareActivity extends FragmentActivity {
  public static final String TAG = "TestMediaShareActivity";
  private Intent intent;
  private KsContentPage mContentPage;

  public static void launch(@NonNull Context context, long posId, @NonNull KsShareData shareData) {
    String shareSchema = shareData.getMediaShareUrl();

    if (TextUtils.isEmpty(shareSchema)) {
      Log.e(TAG, "shareSchema is null");
      return;
    }
    Intent intent = new Intent(context, TestMediaShareActivity.class);
    intent.putExtra("posId", posId);
    intent.putExtra("shareSchema", shareSchema);
    context.startActivity(intent);
  }

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.test_activity_content_page);
    intent = getIntent();
    long posId = intent.getLongExtra("posId", 0L);
    String shareSchema = intent.getStringExtra("shareSchema");
    KsScene adScene = new KsScene.Builder(posId).build();
    mContentPage = KsAdSDK.getLoadManager().loadContentPageBySchema(adScene, shareSchema);
    Log.d(TAG, "TestMediaShareActivity shareSchema= " + shareSchema);

    getSupportFragmentManager().beginTransaction()
        .replace(R.id.container, mContentPage.getFragment())
        .commitAllowingStateLoss();
  }
}
